package com.example.win.android_banduyujia.peopleactivity.activity.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.RadioGroup;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.adapter.ViewPageAdapter;
import com.example.win.android_banduyujia.peopleactivity.fragment.materfragment.EditFragment;
import com.example.win.android_banduyujia.peopleactivity.fragment.materfragment.StatusFragment;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseTitleBarActivity;

import java.util.ArrayList;

/**
 * Created by Win on 2015/8/14.
 */
public class MateralActivity extends BaseTitleBarActivity{
    public static final String  TAG = MateralActivity.class.getSimpleName();

    private RadioGroup   mRadioGroup;
    private ViewPager    mViewPager;

    private  ArrayList<Fragment>  mFragmentList=new ArrayList<Fragment>();
    private  ViewPageAdapter  mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_page_materal);

        InitTitles();
        InitFragment();
        InitViews();
    }

    private void InitTitles() {
        setTitle(R.string.title_text_view_materal);
        showLeftBackButton();
    }

    private void InitFragment() {
            EditFragment editFragment  = new EditFragment();
            StatusFragment statusFragment = new StatusFragment();
            mFragmentList.add(editFragment);
            mFragmentList.add(statusFragment);
    }

    @Override
    protected void onResume() {
        super.onResume();

        mAdapter = new ViewPageAdapter(getSupportFragmentManager(), mFragmentList);
        mViewPager.setAdapter(mAdapter);
    }

    private void InitViews() {
        mRadioGroup = (RadioGroup) findViewById(R.id.radio_group_materal);
        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radio_edit_data:
                         mViewPager.setCurrentItem(0);
                        break;
                    case R.id.radio_review_status:
                        mViewPager.setCurrentItem(1);
                        break;
                    default:
                        break;
                }
            }
        });

        mViewPager = (ViewPager) findViewById(R.id.materal_viewPager);
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i2) { }

            @Override
            public void onPageSelected(int i) {
                switch (i){
                    case 0:
                        mRadioGroup.check(R.id.radio_edit_data);
                        break;
                    case 1:
                        mRadioGroup.check(R.id.radio_review_status);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) { }
        });
    }
}
